package com.gulimall.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gulimall.common.utils.PageUtils;
import com.gulimall.common.utils.Query;
import com.gulimall.order.dao.OrderItemDao;
import com.gulimall.order.entity.OrderItemEntity;
import com.gulimall.order.service.OrderItemService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * RabbitListener 标注在类 + 方法
 * RabbitHandler 标注在方法上
 * RabbitListener + RabbitHandler  通过重载方法可以实现 接收多个队列的消息的功能
 */
@RabbitListener(queues = "test-queue")
@Service("orderItemService")
public class OrderItemServiceImpl extends ServiceImpl<OrderItemDao, OrderItemEntity> implements OrderItemService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<OrderItemEntity> page = this.page(new Query<OrderItemEntity>().getPage(params),
                new QueryWrapper<OrderItemEntity>());

        return new PageUtils(page);
    }

    /**
     * 可接收值
     * Message  原生消息详细信息
     * T<发送的消息类型>
     * Channel
     */
//    @RabbitListener(queues = "test-queue")
    @RabbitHandler
    public void receiveMessage(Message message, List<Integer> nums) {
        System.out.println(Arrays.toString(message.getBody()));

        System.out.println(message);

        System.out.println(nums);

//        System.out.println(channel);
    }

    @RabbitHandler
    public void receiveMessage2(Message message, String msg) {
        System.out.println(message);
        System.out.println(msg);
    }
}

